<template>
  <div>
    <!-- 头部 -->
    <div class="header">
      <p>我的收货地址</p>
      <router-link to="/addsite">
        <div class="addsite">
          <img src="../../assets/site_img/add.png" alt="">
          <p>添加地址</p>
        </div>
      </router-link>
    </div>
    <div style="height: 2.4rem"></div>
    <!-- 内容 -->
    <div class="card" v-for="(item, index) in siteData" :key="index">
      <div class="cardbox">
        <img src="../../assets/site_img/name.png" alt="" class="cardimg">
        <p>{{item.contact}}</p>
      </div>
      <div class="cardbox">
        <img src="../../assets/site_img/phone.png" alt="" class="cardimg">
        <p>{{item.mobile}}</p>
      </div>
      <div class="cardbox">
        <img src="../../assets/site_img/site1.png" alt="" class="cardimg1">
        <div class="sitetext">
          <p>{{item.address}}</p>
        </div>
      </div>
      <div style="height: 0.4rem"></div>
      <div class="cardfooter">
        <p v-if="item.type == 0" @click="okDefault(index)">设为默认地址</p>
        <div class="default" v-else>
          <p>默认地址</p>
        </div>
      </div>
      <!-- 编辑 -->
      <img src="../../assets/site_img/compile.png" alt="" class="compile" @click="showCompile(index)">
      <!-- 删除 -->
      <img src="../../assets/site_img/del.png" alt="" class="del" @click="showwin(index)">
    </div>
    <div style="height: 6rem"></div>
    <!-- 删除 -->
    <div class="winshow" v-if="winshow">
      <div class="an"></div>
      <div class="ming">
        <div class="imgmingtext">
          <p>{{msgtext}}</p>
        </div>
        <div class="snmingbtnbox">
          <div class="imgmingbtn" @click="nonewin()">
            <p>取消</p>
          </div>
          <div class="imgmingbtn" style="width: 2.5rem; border: none"></div>
          <div class="imgmingbtn" @click="delsite()">
            <p>确定</p>
          </div>
        </div>
      </div>
    </div>
    <!-- 编辑 -->
    <div class="winshow" v-if="winshow1">
      <div class="an"></div>
      <div class="ming">
        <div class="imgmingtext">
          <p>{{msgtext}}</p>
        </div>
        <div class="snmingbtnbox">
          <div class="imgmingbtn" @click="nonewin()">
            <p>取消</p>
          </div>
          <div class="imgmingbtn" style="width: 2.5rem; border: none"></div>
          <div class="imgmingbtn" @click="compileSite()">
            <p>确定</p>
          </div>
        </div>
      </div>
    </div>


    <Footer></Footer>
  </div>
</template>

<script>
  import Footer from '../footer/footer'
  export default {
    data(){
      return{
        //  地址信息、
        siteData:'',


        //  弹框
        winshow: false,
        winshow1: false,
        msgtext:'',
        showText: false,
      }
    },
    components:{
      Footer
    },
    created(){
      this.siteList();
    },
    methods:{
      //  请求地址接口
      siteList(){
        let postData = this.$qs.stringify({
          offset:'',
          limit:'',
          storeId: 1,
        });
        this.$axios({
          method:'POST',
          url:'api/address/addressList',
          data:postData
        }).then((res)=>{
          console.log(res.data.msg);
          this.siteData = res.data.data;
        }).catch((err)=>{
          console.log(err);
        })
      },
      //  删除该地址
      delsite(){
        let postData = this.$qs.stringify({
          deliveryId: this.deliveryId,
        });
        this.$axios({
          method:'POST',
          url:'api/address/delete',
          data:postData
        }).then((res)=>{
          console.log(res.data.msg);
          this.$router.replace({
            path:'/newTakesite',
          });
        }).catch((err)=>{
          console.log(err);
        })
      },
      //  设为默认地址
      okDefault(index) {
        let postData = this.$qs.stringify({
          deliveryId: this.siteData[index].deliveryId,
        });
        this.$axios({
          method:'POST',
          url:'api/address/updatetype',
          data:postData
        }).then((res)=>{
          console.log(res.data.msg,'设为默认地址');
          this.$router.replace({
            path:'/newTakesite',
          });
        }).catch((err)=>{
          console.log(err);
        })
      },

      //  编辑地址
      compileSite(){
        this.$router.push({path:'/compileSite',query:{id:this.deliveryId}})
      },

      //  删除
      showwin(index){
        this.winshow = true;
        this.msgtext = '确定删除该地址吗?';
        this.deliveryId = this.siteData[index].deliveryId;
      },
      //  编辑
      showCompile(index){
        this.winshow1 = true;
        this.msgtext = '确定修改该地址吗?';
        this.deliveryId = this.siteData[index].deliveryId;
      },
      nonewin() {
        this.winshow = false;
        this.winshow1 = false;
      },

    },

  }

</script>

<style scoped>
  *{
    margin: 0;
    padding: 0;
  }
  .header {
    width: 100%;
    height: 2.4rem;
    text-align: center;
    background: #609FE0;
    z-index: 999;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }
  .header p {
    line-height: 2.4rem;
    font-size: 1.05rem;
    color: white;
    font-weight: bolder;
  }
  .addsite {
    z-index: 999;
    position: fixed;
    top: 0.5rem;
    right: 0.6rem;
    margin-left: -150px;
    background-image: -webkit-linear-gradient(left,red, white 10%, red 20%, white 30%, red 40%, white 50%,red 60%,white 70%,red 80%,white 90%,red 100%);
    -webkit-text-fill-color: transparent;/* 将字体设置成透明色 */
    -webkit-background-clip: text;
    -webkit-background-size: 200% 50%;
    -webkit-animation: masked-animation 10s linear infinite;
  }
  @keyframes masked-animation {
    0% {
      background-position: 0  0;
    }
    100% {
      background-position: -100%  0;
    }
  }
  .addsite img {
    width: 1.3rem;
    height: 1.3rem;
    vertical-align: bottom;
  }
  .addsite p {
    display: inline;
    font-size: 0.9rem;
    line-height: 1.3rem;
  }
  /* 内容 */
  .card {
    width: 94%;
    /*height: 10rem;*/
    margin-left: 3%;
    background: white;
    border: 1px solid gainsboro;
    border-radius: 0.25rem;
    margin-top: 1rem;
    position: relative;
  }
  .cardbox {
    margin-left: 0.6rem;
    padding-top: 0.3rem;
    position: relative;
  }
  .cardimg {
    width: 1.5rem;
    height: 1.5rem;
    vertical-align: bottom;
  }
  .cardbox p {
    display: inline;
    line-height: 1.6rem;
    font-size: 0.9rem;
    color: #666666;
    margin-left: 0.4rem;
  }
  .cardimg1 {
    width: 1.5rem;
    height: 1.5rem;
    position: absolute;
  }
  .sitetext {
    width: 80%;
    margin-left: 10%;
    background: #f2f2f2;
    padding: 0.1rem 0.7rem;
    border-radius: 0.25rem;
  }
  .cardfooter {
    width: 100%;
    height: 2.4rem;
    border-top: 1px solid gainsboro;
    text-align: center;
  }
  .cardfooter p {
    font-size: 0.88rem;
    line-height: 2.4rem;
    color: #609FE0;
  }
  .default {
    width: 100%;
    height: 2.4rem;
    background: #E63838;
    border-radius: 0.25rem;
  }
  .default p {
    font-size: 0.88rem;
    line-height: 2.4rem;
    color: white;
  }
  /* 删除 */
  .del {
    width: 1.4rem;
    height: 1.4rem;
    position: absolute;
    top: 0.5rem;
    right: 0.6rem;
  }
  /* 编辑 */
  .compile {
    width: 1.4rem;
    height: 1.5rem;
    position: absolute;
    top: 0.35rem;
    right: 3rem;
  }

  /* 弹框 */
  .winshow {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
  }
  .an {
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    background: black;
    opacity: 0.4;
  }
  .ming {
    width: 80%;
    height: 10rem;
    background: white;
    position: fixed;
    top: 30%;
    left: 10%;
    border-radius: 0.25rem;
  }
  .snmingbtnbox {
    text-align: center;
    border-top: 1px solid gainsboro;
  }
  /*  上传图片弹出框提示  */
  .imgmingtext {
    text-align: center;
    height: 6.8rem;
  }
  .imgmingtext p {
    line-height: 6.8rem;
    font-size: 0.98rem;
    color: #666666;
  }
  /*图片按钮*/
  .imgmingbtn {
    display: inline-block;
    width: 5rem;
    border: 1px solid gainsboro;
    border-radius: 0.25rem;
    margin-top: 0.6rem;
    /*margin-left: 35%;*/
  }
  .imgmingbtn p {
    line-height: 1.9rem;
    color: #666666;
    font-size: 0.88rem;
  }
</style>